#  Copyright (c) ZenML GmbH 2023. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at:
#
#       https://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
#  or implied. See the License for the specific language governing
#  permissions and limitations under the License.
"""Unit tests for the Facets materializer."""

from contextlib import ExitStack as does_not_raise

import pandas as pd

from tests.unit.test_general import _test_materializer
from zenml.integrations.facets.materializers.facets_materializer import (
    FacetsMaterializer,
)
from zenml.integrations.facets.models import FacetsComparison


def test_facets_materializer(clean_client):
    """Test the Facets materializer."""
    df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=["a", "b", "c"])

    for i in range(3):
        facets_comparison = FacetsComparison(
            datasets=[{"name": f"dataset_{i}", "table": df} for j in range(i)]
        )

        with does_not_raise():
            _test_materializer(
                step_output=facets_comparison,
                materializer_class=FacetsMaterializer,
                assert_data_exists=False,
                assert_data_type=False,
                assert_visualization_exists=True,
            )
